/**
 * DumpFlightInfoDbMngr.java
 * 2010-1-25
 */
package com.dlplay.flightinfo.db;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import javax.persistence.EntityManager;

import com.dlplay.flightinfo.data.AirFlightCode;
import com.dlplay.flightinfo.data.Airport;
import com.dlplay.flightinfo.data.AirportTerminalCode;
import com.dlplay.flightinfo.data.CityCode;
import com.dlplay.flightinfo.data.EMailRegister;
import com.dlplay.flightinfo.data.FlightInfo;
import com.dlplay.flightinfo.data.RealTimeFlightInfo;

/**
 * @author zhao yu
 * a fake db for testing
 */
public class DumpFlightInfoDbMngr implements FlightInfoDbMngr {
	private static final Logger log = Logger.getLogger(DumpFlightInfoDbMngr.class.getName());
	private List<RealTimeFlightInfo> rtFlightInfos = new ArrayList<RealTimeFlightInfo>();
	private List<EMailRegister> eMailRegs = new ArrayList<EMailRegister>();
	private List<Airport> airports = new ArrayList<Airport>();
	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#addAirport(com.dlplay.flightinfo.data.Airport)
	 */
	@Override
	public void addAirport(Airport airport) {
		log.info("add new airport "+airport);
		airports.add(airport);

	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#addFlightRegister(com.dlplay.flightinfo.data.EMailRegister)
	 */
	@Override
	public void addFlightRegister(EMailRegister reg) {
		log.info("register: "+reg);
		eMailRegs.add(reg);
	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#addRealTimeFlightInfo(com.dlplay.flightinfo.data.RealTimeFlightInfo)
	 */
	@Override
	public void addRealTimeFlightInfo(RealTimeFlightInfo rtFlightInfo) {
		log.info("info: "+rtFlightInfo);		
		rtFlightInfos.add(rtFlightInfo);
		log.info("add a new record");
	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#deleteAirport(com.dlplay.flightinfo.data.AirportTerminalCode)
	 */
	@Override
	public void deleteAirport(AirportTerminalCode terminal) {
		// TODO Auto-generated method stub
		log.info("delete airport "+terminal);

	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#getAirport(com.dlplay.flightinfo.data.AirportTerminalCode)
	 */
	@Override
	public Airport getAirport(AirportTerminalCode terminal) {
		log.info("find aiport: "+terminal);
		for(Airport airport:airports)
		{
			if(airport.getIdentifier().equals(terminal))
			{
				return airport;
			}
		}		
		return null;
	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#getAirports()
	 */
	@Override
	public List<Airport> getAirports() {
		return airports;
	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#getEntityManager()
	 */
	@Override
	public EntityManager getEntityManager() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#getFlightEmailRegister(com.dlplay.flightinfo.data.AirFlightCode, java.lang.String)
	 */
	@Override
	public EMailRegister getFlightEmailRegister(AirFlightCode flightNum,
			String email) {
		log.info("find register: "+flightNum+" email: "+email);
		for(EMailRegister reg: eMailRegs)
		{
			if(reg.getFlightNum().equals(flightNum)&&reg.getEmail()==email)
			{
				return reg;
			}
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#getFlightInfo(com.dlplay.flightinfo.data.CityCode, com.dlplay.flightinfo.data.CityCode, java.util.Date)
	 */
	@Override
	public List<FlightInfo> getFlightInfo(CityCode from, CityCode to, Date date) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#getFlightInfo(com.dlplay.flightinfo.data.AirFlightCode, java.util.Date)
	 */
	@Override
	public FlightInfo getFlightInfo(AirFlightCode flightNumber, Date date) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#getRealTimeFlightInfo(com.dlplay.flightinfo.data.AirFlightCode)
	 */
	@Override
	public RealTimeFlightInfo getRealTimeFlightInfo(AirFlightCode flightNumber) {
		log.info("flightNumber: "+flightNumber);
		for(RealTimeFlightInfo info:rtFlightInfos)
		{
			if(info.getNumber().equals(flightNumber))
			{
				return info;
			}
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#getRegisteredFlights()
	 */
	@Override
	public List<AirFlightCode> getRegisteredFlights() {
		List<AirFlightCode> flights = new ArrayList<AirFlightCode>();
		for(EMailRegister reg:eMailRegs){
			if(!flights.contains(reg.getFlightNum()))
			{
				flights.add(reg.getFlightNum());
			}
		}
		return flights;
	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#updateAirport(com.dlplay.flightinfo.data.Airport)
	 */
	@Override
	public void updateAirport(Airport airport) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see com.dlplay.flightinfo.db.FlightInfoDbMngr#updateRealTimeFlightInfo(com.dlplay.flightinfo.data.RealTimeFlightInfo)
	 */
	@Override
	public void updateRealTimeFlightInfo(RealTimeFlightInfo info) {
		log.info("info: "+info);

	}

}
